package com.ljt.service.impl;

import com.ljt.entity.RoleEntity;
import com.ljt.entity.UserEntity;
import com.ljt.repository.RoleDao;
import com.ljt.service.RoleService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by wb-ljt251780 on 2017/7/28.
 */
@Service
@Transactional
public class RoleServiceImpl implements RoleService {
    @Resource
    private RoleDao roleDao;
    @Override
    public Page<RoleEntity> findAll(Pageable pageable) {
        return roleDao.findAll(pageable);
    }

    @Override
    public RoleEntity findById(Long id) {
        return roleDao.findOne(id);
    }

    @Override
    public void saveOrUpdate(RoleEntity roleEntity) {
        if(roleEntity.getId()!=null){
            RoleEntity one = roleDao.findOne(roleEntity.getId());
            one.setName(roleEntity.getName());
            roleDao.saveAndFlush(one);
        }else{
            roleDao.save(roleEntity);
        }
    }
}
